//
//  ReweetedStatusView.swift
//  sinaweibo
//
//  Created by mac on 15/11/16.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit
import SnapKit

class ReweetedStatusView: UIView {

    var bottomConstraints: Constraint?
    
    var reweetedStatus: Status? {
        didSet{
            reweetedLabel.text = reweetedStatus?.text
            self.bottomConstraints?.uninstall()
            if let picUrls = reweetedStatus?.imageURLs where picUrls.count > 0 {
                
                imageView.imageURLs = picUrls
                imageView.hidden = false
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraints = make.bottom.equalTo(imageView.snp_bottom).constraint
                })
                
            }else {
                imageView.hidden = true
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraints = make.bottom.equalTo(reweetedLabel.snp_bottom).constraint
                })
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI() {
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(reweetedLabel)
        addSubview(imageView)
        
        reweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top).offset(statusCellMargin)
            make.left.equalTo(snp_left).offset(statusCellMargin)
        }
        
        imageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(reweetedLabel.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(reweetedLabel.snp_left)
//            make.height.equalTo(100)
//            make.width.equalTo(100)
        }
        
        self.snp_makeConstraints { (make) -> Void in
             self.bottomConstraints = make.bottom.equalTo(imageView.snp_bottom).constraint
        }
        
    }
    
    private lazy var reweetedLabel:UILabel = UILabel(title: "转发微博", size: 14, color: UIColor.lightGrayColor(), margin: statusCellMargin)
    
    private lazy var imageView:StatusPictureView = StatusPictureView()
}
